<?php
require 'inc_security.php';

$myform = new generate_form();
$myform->add('pic_title','pic_title',0,0,'Tiêu đề - mô tả');
$myform->add('pic_active','pic_active',1,0,0);
$myform->add('pic_position','pic_position',1,0,0);
$myform->addTable($bg_table);
$myform->removeHTML(0);
$action = getValue('action','str','POST','');
if($action == 'execute'){
    $bg_errorMsg .= $myform->checkdata();
    $upload = new upload('pic_picture',$bg_filepath,$bg_extension,$limit_size);
    $filename = $upload->file_name;
    if($filename){
        $myform->add('pic_picture','filename',0,1,'');
        foreach($arr_resize as $type => $arr){
			resize_image($bg_filepath, $filename, $arr["width"], $arr["height"], $arr["quality"], $type);
		}
    }
    $bg_errorMsg .= $upload->show_warning_error();
    if($bg_errorMsg == ''){
        $db_insert = new db_execute($myform->generate_insert_SQL());
        //echo $myform->generate_insert_SQL();
        redirect('listing.php');
    }
}
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="vi" lang="vi" xmlns:og="http://ogp.me/ns#" xmlns:fb="https://www.facebook.com/2008/fbml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?=$load_header?>
</head>
<body>
<div class="module_header bold fix"><?=$module_name?></div>
<div id="wrapper">
    <?print_error_msg($bg_errorMsg)?>
	<?php $form = new form();?>
	<?=$form->form_open()?>
    <?=$form->textnote('Các trường có dấu (<span class="form-asterick">*</span>) là bắt buộc nhập')?>
	<?=$form->text(array('label'=>'Tiêu đề - mô tả','name'=>'pic_title','id'=>'pic_title','value'=>getValue('pic_title','str','POST',''), 'placeholder'=> 'Tiêu đề không dài quá 255 ký tự'),0,'span6')?>
    <?=$form->text(array('label'=>'Thứ tự','name'=>'pic_position','id'=>'pic_position','value'=>getValue('pic_position','int','POST',0)))?>
    <?=$form->checkbox(array('label'=> 'Xuất bản', 'name'=> 'pic_active', 'id'=> 'pic_active', 'value'=>1 ,'currentValue'=>getValue('pic_active','int','POST',1), 'helptext'=> 'Xuất bản ra trang (active)'))?>
    <?=$form->getFile(array('label'=>'Ảnh','title'=>'Ảnh','name'=>'pic_picture','id'=>'pic_picture','helptext'=>'Cỡ 950 x 350'))?>
    <?=$form->form_action(array('label'=>array('Thêm mới','Nhập lại'),'type'=>array('submit','reset')))?>
	<?=$form->form_close()?>
</div>
</body>
</html>